<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>列表渲染</h2>

      <h4>数组遍历</h4>
      <ul>
        <!-- 其中 arr 是源数据的数组，而 item 是迭代项的别名 -->
        <!-- for in 和 for of 完全等价的 -->
        <li v-for="item in arr">{{ item }}</li>
      </ul>

      <hr />

      <p v-for="({name, id}, index) of arr2">
        {{ name }} - {{id}} - {{ index }}
      </p>

      <h4>对象遍历</h4>
      <!-- 对象遍历也可以使用in和of -->
      <!-- 对象遍历的时候三个参数，分别是value, key, index -->
      <ul>
        <li v-for="(value, key, index) in myObject">
          {{ value }} - {{ key }} - {{ index }}
        </li>
      </ul>

      <h4>使用范围值</h4>
      <!-- <ul> -->
      <!-- 10相当于[1,2,3,4,5,6,7,8,9,10] -->
      <!-- <li v-for="item in 10">{{ item }}</li>
      </ul> -->

      <!-- 可以做嵌套 -->
      <div v-for="i in 9">
        <span v-for="j in i"> {{ i }} * {{ j }} = {{ i * j }} </span>
      </div>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      const { createApp } = Vue;

      createApp({
        data() {
          return {
            arr: [1, 2, 3, 4, 5],
            arr2: [
              {
                id: 1,
                name: "zhangsan",
              },
              {
                id: 2,
                name: "lisi",
              },
            ],
            myObject: {
              title: "How to do lists in Vue",
              author: "Jane Doe",
              publishedAt: "2016-04-10",
            },
          };
        },
      }).mount("#app");
    </script>
  </body>
</html>
